/**
 * 
 */
package com.yidu.view;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.yidu.bean.TbMenu;
import com.yidu.bean.TbMenuType;
import com.yidu.bean.TbShop;
import com.yidu.commom.Tools;
import com.yidu.message.Message;
import com.yidu.message.Pages;
import com.yidu.service.TbMenuTypeService;
import com.yidu.service.TbShopService;

/**
 * 
 * @author liutao
 * @data 2018年7月16日
 * @version 1.0
 */
@Controller
@RequestMapping("/menutype")
public class TbMenuTypeAction {

	//打印控制台
	Logger logger = Logger.getLogger(TbMemberAction.class);

	//消息信息类
	Message msg = new Message();

	//json
	ObjectMapper mapper = new ObjectMapper();

	@Resource
	private TbMenuTypeService tbMenuTypeServiceImpl ;
	
	/**
	 * 增加和修改
	 * @param session web存储空间
	 * @param me 菜单对象
	 * @return 页面跳转
	 */
	@RequestMapping("addOrUpdate")
	@ResponseBody
	public Message addOrUpdate(HttpSession session, TbMenuType me) {
		System.out.println("wwwwwwwwwwwwwwwww"+me.getMtId());
		if(Tools.isEmpty(me.getMtId())){
			me.setMtId(UUID.randomUUID().toString());
			tbMenuTypeServiceImpl.save(me);
			me=new TbMenuType();
		}else{
			tbMenuTypeServiceImpl.update(me);
		}
		msg.setMsg("成功");
		msg.setNum(1);
		return msg;
	}
	/**
	 * 修改
	 * @param id 菜单id
	 * @return 页面跳转
	 */
	@RequestMapping("deleteFood")
	@ResponseBody
	public String deleteMember(String id){
		String str=null;
		if(!Tools.isEmpty(id)){
			int row= tbMenuTypeServiceImpl.delete(id);
			if(row>0){
				str="ok";
			}
		}
		return str;

	}

	/**
	 * 根据ID查询对象类型
	 * 
	 * @param id
	 * @param response
	 * @return
	 */
	@RequestMapping("/showUpdate")
	@ResponseBody
	public Object showUpdate(String mtId){
			logger.info("进入显示...");
			
			//HttpServletResponse response = Tools.getResponse();
			
			TbMenuType member = tbMenuTypeServiceImpl.findByIds(mtId);
			
			//logger.info(gson.toJson(vo));
			
		 return member;
		  
	}

	/**
	 * 查询所有和条件查询分页
	 * @param response 响应
	 * @param me 菜单对象
	 * @param page 页数
	 * @param limit 行数
	 * @return
	 */
	@RequestMapping("menuFindAll")
	@ResponseBody
	public Map<String, Object> findAll(HttpServletResponse response,TbMenuType me,int page,int limit) {

		response.setCharacterEncoding("UTF-8");
		Pages pages = new Pages();
		pages.setPage(page);
		pages.setTotalRows(limit);
		Map<String,String> map=new HashMap<>();
		map.put("mtName", me.getMtName());
		map.put("start", String.valueOf(pages.getStart()));
		map.put("rows", String.valueOf(pages.getTotalRows()));
		List<TbMenuType> list = tbMenuTypeServiceImpl.findAllPage(map);
		Map<String, Object> maps = new HashMap<>();
		//需要符合layUI格式，code msg count data
		maps.put("code", 0);
		maps.put("msg", "1");
		maps.put("count", tbMenuTypeServiceImpl.findTotalRows(me));
		maps.put("data", list);
		me=new TbMenuType();

		return maps;
	}

	@RequestMapping("/findByIds")
	@ResponseBody
	public List<TbMenuType> findByIds(String shopId){
		System.out.println("这是一个根据id查询店面中菜品类型的的方法");
		List<TbMenuType> shop = tbMenuTypeServiceImpl.findById(shopId);
		return shop;
	}
	
	@RequestMapping("/findAll")
	@ResponseBody
	public List<TbMenuType> findAlls(){
		System.out.println("这是一个根据id查询店面中菜品类型的的方法");
		List<TbMenuType> shop = tbMenuTypeServiceImpl.findAll();
		return shop;
	}
	
}
